<template>
  <div :class="{'hidden':hidden}" class="pagination-container">
    <el-pagination
        :background="background"
        :hide-on-single-page="true"
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :layout="layout"
        :page-sizes="pageSizes"
        :total="total ? total : 0"
        v-bind="$attrs"
    >
      <el-button class="refresh-button" icon="el-icon-refresh" style="font-size:18px;"
                 title="刷新" @click="refreshTable"/>
    </el-pagination>
  </div>
</template>

<script>

export default {
  name: 'Pagination',
  props: {
    total: {
      required: true,
      type: Number
    },
    page: {
      type: Number,
      default: 1
    },
    limit: {
      type: Number,
      default: 20
    },
    pageSizes: {
      type: Array,
      default() {
        return [20, 40, 60, 80, 100]
      }
    },
    layout: {
      type: String,
      default: 'prev, pager, next, total'
    },
    background: {
      type: Boolean,
      default: false
    },
    autoScroll: {
      type: Boolean,
      default: true
    },
    hidden: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    pageSize: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    }
  },
  methods: {
    refreshTable() {
      this.$emit('pagination', {page: this.currentPage, limit: this.pageSize})
    }
  },
  watch: {
    'pageSize' (val) {
      this.$emit('pagination', {page: this.currentPage, limit: val})
    },
    'currentPage' (val) {
      this.$emit('pagination', {page: val, limit: this.pageSize})
    }
  }
}
</script>

<style scoped>
.pagination-container {
  background: transparent;
  padding: 5px 5px;
  margin-top: 5px;
}

.pagination-container.hidden {
  display: none;
}
</style>

<style>
.el-pagination__editor.el-input .el-input__inner {
  line-height: 28px;
}

.v-modal {
  position: relative;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  opacity: 0.5;
  background: #000000;
}
</style>
